#!/usr/bin/env python
# encoding: utf-8
'''
@author: 王震
@license: 四川凡狼科技有限公司
@contact: 2668985108@qq.com
@file: message.py
@time: 2022/2/16 10:17
@desc:
'''

from flask import request, Blueprint
from app.business.message.message import *
from app.public.sqlMethods import auto

message = Blueprint("message", __name__, url_prefix='/api')


@message.route("/add/message", methods=['POST'])
@auto.login_required
def _add_message():
    """
    创建留言
    :return:
    """
    data = request.json
    return add_message(data=data)


@message.route('/get/message', methods=['GET'])
@auto.login_required
def _get_message():
    """
    客户端获取留言列表
    :return:
    """
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    return get_message(page_number=page_number, page_size=page_size)


@message.route('/get/system/message', methods=['GET'])
@auto.login_required
def _get_system_message():
    """
    管理系统获取留言列表
    :return:
    """
    page_number = request.args.get('pageNumber', 1)
    page_size = request.args.get('pageSize', 10)
    return get_system_message(page_number=page_number, page_size=page_size)


@message.route('/to/examine/message', methods=['PUT'])
@auto.login_required
def _examine_message():
    """
    修改留言状态
    :return:
    """
    data = request.json
    return examine_message(data=data)


@message.route('/del/message', methods=['DELETE'])
def _del_message():
    """
    删除留言
    :return:
    """
    data = request.json
    id = data['id']
    return del_message(id=id)
